<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/resources/modular/plugin/taglibs.jsp" %>
<!doctype html>
<head content="-我的">
    <%@ include file="/resources/modular/head/inside_head.jsp" %>
</head>
<body class="GC_Menu_7" name="GC_indvidual">

<%@ include file="/resources/modular/plugin/mainMenu.jsp" %>

<div class="page" name="GC_individual_uploadlogo">

    <%@ include file="/resources/modular/plugin/mainTopMenu.jsp" %>

    <%@ include file="/resources/modular/plugin/individualMeun.jsp" %>

    <div class="page_right">
        <div class="my_uploadLogodv">
            <%--<span id="GC_showlogo_span"><img id="GC_show_file" src="${basePath}resources/images/web/v2/my/logoshangbiao.png" alt=""></span>--%>
                <span id="GC_showlogo_span" style="width:100px;height:100px;display:block;border-radius:50%; overflow:hidden;"><img id="GC_show_file" src="<c:if test="${islogo == false}">${basePath}</c:if>${logo}" alt=""></span>
            <span class="my_uploadLogo_changebtn">更换图片<input type="file" id="GC_logo_file" name="logo" multiple="multiple"></span>
        </div>
        <p class="my_luploadLogo_p"><a class="my_luploadLogo_pbtn1" id="GC_uploadlogo_confirm" href="javascript:;">确认</a>  <a class="my_luploadLogo_pbtn2" href="javascript:;">取消</a></p>
    </div>
</div>
</body>
</html>
<%@ include file="/resources/modular/foot/inside_footer.jsp" %>
<script type="text/javascript">

    var defaultlogo = "<c:if test="${islogo == false}">${basePath}</c:if>${logo}";

    $(".my_luploadLogo_p").hide();//确认上传

    $(".my_luploadLogo_pbtn1").on("click", function(){
        $(".my_luploadLogo_p").stop().hide();
        //alert("图片上传成功", "cur");

        //创建FormData对象
        var forData = new FormData();
        forData.append('logo', $('#GC_logo_file')[0].files[0]);

        $.ajax({
            url:'${basePath}v2/individual/uplaodLogo',
            type:'POST',
            data:forData,
            cache: false,
            contentType: false,
            processData: false,
            error: function (response) {
                $errorMsg(response);
            },
            success:function(ret){
                if(ret.result){
                    alert(ret.info,"cur");
                }else{
                    alert(ret.info);
                }
            }
        });
    });

    //取消上传
    $(".my_luploadLogo_pbtn2").on("click", function(){
        $(".my_luploadLogo_p").stop().hide();
        $("#GC_show_file").attr("src", defaultlogo).show();
        $("#GC_new_show_file").hide();
    });

    <%--  预览图片 --%>
    $("#GC_logo_file").change(function () {
        var files = this.files,img = new Image();
        if(window.URL) {
            var file = files[0];
            img.src = window.URL.createObjectURL(file);
            img.onload = function(e) {
                window.URL.revokeObjectURL(this.src); //图片加载后，释放object URL
            }
            $("#GC_show_file").attr("src", img.src);
        }else if(window.FileReader){
            var file = files[0];
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function(e){
                img.src = this.result;
            }
            $("#GC_show_file").attr("src", img.src);
        }else{
            $("#GC_show_file").hide();
            $("#GC_logo_file").select();
            $("#GC_logo_file").blur();
            var newPreview = document.getElementById("GC_new_show_file");
            if (newPreview == null) {
                newPreview = document.createElement("div");
                newPreview.setAttribute("id", "GC_new_show_file");
            }
            newPreview.style.width = $("#GC_show_file").width()+"px";
            newPreview.style.height =  $("#GC_show_file").height()+"px";
            newPreview.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + document.selection.createRange().text + "')";
            /*newPreview.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src='"+newfile+"')";*/
            newPreview.style.display = "block";
            document.getElementById("GC_show_file").style.display = "none";
            document.getElementById("GC_showlogo_span").appendChild(newPreview);

        }

        $(".my_luploadLogo_p").show();//确认上传

    });

</script>